package com.ftg.learn.controller;

import com.ftg.learn.dto.Person;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 控制器
 * Rest : 表述性状态描述
 *
 * @author 布衣
 */
@RestController
public class FirstController {

    //hello是java调用名称
    //不是http调用地址
    @GetMapping("/list")
    public String hello(
            @RequestParam(value = "name", required = false, defaultValue = "张三") String name,
            @RequestParam(value = "age", required = false, defaultValue = "10") Integer age
    ) {
        return "hello world" + name + age;
    }

    /**
     * 一个方法只能一个RequestBody 声明的类
     *
     * @param p
     * @return
     */
    @PostMapping("/save")
    public String hello1(@RequestBody Person p) {
        return "我是添加" + p.toString();
    }


    @PutMapping("/modify/{id}")
    public String modify(@PathVariable("id") String id) {
        return "modify" + id;
    }

    @DeleteMapping("/del/{id}")
    public String del(
            @RequestParam("name") String name,
            @PathVariable(value = "id",required = false) String id
            , @RequestBody Person p) {
        return "del" + id+name+p.toString();
    }

//    restful  满足rest协议的方法  get(查询) post(添加) put(修改) delete(删除) header(头)

}
